import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * 
 * Receiver thread which listens on a port for incoming packets
 * and adds them to MDRRBuffer instance for scheduling
 */
public class MDRRReceiver extends Thread {

	private int port;
	private MDRRBuffer buffer;

	public MDRRReceiver(int port, MDRRBuffer buffer)
	{
		this.port = port;
		this.buffer = buffer;
	}
	
	@Override
	public void run() {
		try
		{
			DatagramSocket socket = new DatagramSocket(port);

			while (true)
			{
				byte[] buf = new byte[MDRRBuffer.MAX_PACKET_SIZE];
				DatagramPacket packet = new DatagramPacket(buf, buf.length);
				socket.receive(packet);
				
				buffer.addPacket(packet);
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}


}
